<template>
  <div class="home">
    这是home页面
    <button @click="getInfo">发送请求</button>
    <button @click="getErr">请求错误</button>
    <hr />
    <div v-for="(item, index) in list" :key="index">
      <p>名字：{{ item.name }}</p>
      <p>年纪：{{ item.age }}</p>
      <p>性别：{{ item.gender }}</p>
      <hr />
    </div>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: "Home",
  components: {},
  // 数据信息
  data() {
    return {
      list: [],
    };
  },
  methods: {
    // 发送请求
    getInfo() {
      this.$http({
        method: "get",
        url: "/user",
        data: {},
      })
        .then((res) => {
          // console.log(res, "相应的数据");
          if (res.status) {
            this.list = res.data;
          }
        })
        .catch((err) => {
          console.log(err, "错误");
        });
    },

    // 错误请求

    getErr() {
      this.$http({
        method: "get",
        url: "/usersss",
        data: {},
      })
        .then((res) => {
          console.log(res, "相应的数据");
        })
        .catch((err) => {
          console.log(err, "错误");
        });
    },
  },
};
</script>
